const CompressionPlugin = require("compression-webpack-plugin")
module.exports = {
    productionSourceMap: false,
    publicPath: '/',
    devServer: {
        open: true, //浏览器自动打开页面
        host: "0.0.0.0", //如果是真机测试，就使用这个IP
        port: 80,
        proxy: {
                //配置跨域
                '/api': {
                    target: '127.0.0.1',
                    ws:true,
                    changOrigin:true,
                    pathRewrite:{
                        '^/api':'/'
                    }
                }
            },
        disableHostCheck: true
    },
    configureWebpack: config => {
        if (process.env.NODE_ENY === 'production') {
            config.plugins.push(
                new CompressionPlugin({
                filename: '[path].gz[query]',
                algorithm: 'gzip',
                text: /\.js$|\.html$|\.css/,
                threshold: 10240,
                deleteOrighinalAssets: false,
                minRatio: 0.8
                })
            )
        }
        return {
            performance: {
                hints:'warning',
                //入口起点的最大体积
                maxEntrypointSize: 50000000,
                //生成文件的最大体积
                maxAssetSize: 30000000,
                //只给出 js 文件的性能提示
                assetFilter: function(assetFilename) {
                    return assetFilename.endsWith('.js');
                }
            }
        }
    },
    css: {
        loaderOptions: {
            sass: {
                additionalData: `@import "~@/css/scss/variable.scss";`
            }
        }
    }
  }